package com.summer.Collection.msb;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test02 {
    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);
        //增加
        list.add(1,5);
        System.out.println(list);
        //修改
        list.set(0,8);
        System.out.println(list);
        //删除
        list.remove(2);//在集合中存入的是Integer类型的数据时，调用的remove方法是:remove(int index);
        list.add("abc");
        list.remove("abc");
        System.out.println(list);
        Object o = list.get(3);
        System.out.println(o);
        //

        //遍历
        for (int i = 0; i <list.size() ; i++) {
            System.out.print(list.get(i));
        }
        System.out.println();
        //遍历增强
        for (Object obj:list
             ) {
            System.out.print(obj);
        }
        System.out.println();
        //逆向遍历
        ListIterator<Object> iterator1 = list.listIterator();
        System.out.println("逆向遍历");
        while (iterator1.hasPrevious()){
            System.out.print(iterator1.previous());
        }
        System.out.println();
        //遍历迭代器
        Iterator<Object> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next());
        }
        System.out.println();

    }

}
